package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.global.Column;
import com.dengbw.systemtransfer.mapper.SysCorpStationMapper;
import com.dengbw.systemtransfer.model.db.SysCorpStation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author dengbw
 * @date 2021年11月26日 3:36 下午
 */
@Service
public class SysCorpStationService {
    SysCorpStationMapper mapper;

    @Autowired
    public SysCorpStationService(SysCorpStationMapper mapper) {
        this.mapper = mapper;
    }

    public void saveSysCorpStation(String corpId, Long subId, String zhudiwangId, String zhudiwangBianhao) {
        List<SysCorpStation> stations = mapper.queryList(v -> v.eq(Column.DING_CORP_ID, corpId).eq(Column.SUB_ID, subId));
        if (CollectionUtils.isEmpty(stations)) {
            SysCorpStation sysCorpStation = new SysCorpStation();
            sysCorpStation.setDingCorpId(corpId);
            sysCorpStation.setSubTenantId(subId);
            sysCorpStation.setVillageId(zhudiwangId);
            sysCorpStation.setVillageCode(zhudiwangBianhao);
            mapper.insert(sysCorpStation);
        }
    }
}
